﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Filters;

namespace WebApiCoreDemo.Api.Filters
{
    public class CustomServiceFilterAttribute : Attribute, IFilterFactory
    {
        private Type _filterType = null;
        public CustomServiceFilterAttribute(Type type)
        {
            _filterType = type;
        }

        public bool IsReusable => true;

        public IFilterMetadata CreateInstance(IServiceProvider serviceProvider)
        {
            object obj = serviceProvider.GetService(this._filterType);
            return (IFilterMetadata)obj;
        }
    }
}
